var config = require('../../config.js');
var common = require('../utils/common.js');
var util=require('../utils/util.js');
/**
 * data  参数
 * tab_page
 */
function load_page(data, currentPage, tab_tab_list, page) {
  wx.request({
    url: config.notifications + '/search/findByTypeAndAppScope',
    data: data,
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      var data = res.data;
      var templist = tab_tab_list.list;
      var notifications = data._embedded.notifications;
      for (var i = 0; i < notifications.length; i++) {
       // notifications[i].time = formate(notifications[i].time);
        //var time = formate(notifications[i].time);
        var time = notifications[i].time;
        notifications[i].time = time.substring(0, 10);
      }

      templist = templist.concat(notifications);
        tab_tab_list.list = templist;
        tab_tab_list.page = currentPage;
       

      time
        page.setData({
          list: templist
        });

    }
  })

}

function load_list(data, currentPage, tab_tab_list, page) {
  wx.request({
    url: config.notifications + '/search/findByTypeAndAppScope',
    data: data,
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      var data = res.data;
      var notifications = data._embedded.notifications;
      for(var i=0;i<notifications.length;i++){
        var time = notifications[i].time;
        //var time = util.handletoLocal(notifications[i].time);
        time = time.substring(0, 10);
        notifications[i].time =time;
      }

      var templist = notifications;
      tab_tab_list.list = templist;
      tab_tab_list.page = currentPage;
      tab_tab_list.pageSize = data.page.totalPages;
      page.setData({
        list: templist
      });
    }
  });
}


function add0(m) { return m < 10 ? '0' + m : m }
function formate(shijianchuo) {
  //shijianchuo是整数，否则要parseInt转换
  var time = new Date(shijianchuo);
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var s = time.getSeconds();

  console.log(y+'-'+m+'-'+d);
  //return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
  return  y + '/' + add0(m) + '/' + add0(d);
}

module.exports = {
  load_list: load_list,
  load_page: load_page
}